package com.chinasofti.study.ma.container;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;

public class HashMapTest {
	public static void main(String[] args) {
		Random rand = new Random();
		Map<Integer, Integer> countMap = new HashMap<Integer, Integer>();
		
		for(int i = 0;i < 1000; i++) {
			int num = rand.nextInt(4);
			Integer count = countMap.get(num);
			
			if(count == null) {
				countMap.put(num, 1);
			}else {
				countMap.put(num, count+1);
			}
		}
		
		for(Map.Entry<Integer, Integer> entry : countMap.entrySet()) {
			System.out.println(entry.getKey() + "出现了" + entry.getValue() + "次");
		}
	}
}
